package com.neaten.functionArrangement.exceptionHandle;

import com.neaten.functionArrangement.common.Result;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.omg.CORBA.SystemException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice
public class ExceptionAdvice {
    public static Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class);

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        Class<? extends Exception> aClass = e.getClass();
        String name = aClass.getName();
        e.printStackTrace();
        String res = e.getMessage();
        if (!name.contains("RuntimeException")) {
            res = name + ": " + e.getMessage();
        }
        return Result.fail(res);
    }
}



